   {Pseudotrans - Codificador de pseudocodigo a lenguaje pascal
    Copyright (C) 2006  Alejandro Lucas Baldres, Nicolas Secreto
    Copyright (C) 2011  Alejandro Lucas Baldres

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}
(**************************************************************)
{PROGRAMACION: ALEJANDRO LUCAS BALDRÉS                         }
{FECHA: 25/09/06                                               }
{LICENCIA: GNU/GPL                                             }
{--------------------------------------------------------------}
{Unidad de cambio de Operadores			       }
{Unit of Operators change}
{--------------------------------------------------------------}
{COMPILADO CON FREEPASCAL / Compiling with Freepascal          }
//Comment Modify: 12/10/2011

unit Operadores;

interface
uses
StrUtils,SysUtils;

procedure Cambio_Operadores (var Cadena:String;Op_Pascal,Operador:string;
				resta:integer;Valido,Val2_Pal_Res:boolean);

implementation
///////////////////////////////////////////////////Procedimientos de operaciones / Operations procedures
procedure Cambio_Operadores (var Cadena:String;Op_Pascal,Operador:string;
				resta:integer;Valido,Val2_Pal_Res:boolean);
 var
 Pos_ope,i:Integer;
 aux:string;
 
 begin
 aux:=uppercase(Cadena);
 Pos_ope:=findPart(operador,aux);//Busco el operador en la linea leida / Search the operator in the read line
 delete(aux,Pos_ope,length(operador));//Borro el operador / delete the operator
 while Pos_ope>0 do
 	begin
	i:=(Pos_ope-1);
	//Valido es un booleano que determina si es una palabra reservada o pertenece a una parte de una variable
	//Valido is a boolean what determine if is a reserved word o is belong to variable
 	if (Valido) and (i>0) then
 		if Cadena[i]<>' ' then
 			resta:=-100;
 	if Val2_Pal_Res then
 		if (length(cadena)<>length(operador)) then
 			resta:=-100;
	//Fin de validacion / End of validation
 	if resta<>-100 then
	  Cadena:=Copy(Cadena,1,Pos_ope-resta)+Op_Pascal+Copy(Cadena,Pos_ope+length(operador),Length(Cadena)-(Pos_ope-1+length(operador)));
	if FindPart('(',Op_Pascal)>0 then
		insert(')',cadena,length(Cadena));
	//Determino si se declara una cadena con longitud / Determine if declare a string with longitude
        if Op_pascal='String' then
	  begin
	  for i:=0 to 9 do 
	   begin
	   Pos_ope:=findPart(IntToStr(i),Cadena);
	   if Pos_ope>0 then break;
	   end;
	  if Pos_ope>0 then
		begin
		insert('(',Cadena,FindPart('String',cadena)+7);
		insert(')',Cadena,Length(Cadena));
		end;
	  end;
	//Fin de Determinación / End of determination
 	Pos_ope:=findPart(operador,aux);
 	delete(aux,Pos_ope,length(operador));
 	end;
 end;
///////////////////////////////////////////////Fin de procedimientos de operaciones / End of procedures of operations
end.
